import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';

export default {

  //初始化选择账套的options
  getSetOfBooks(){
    return httpFetch.get(config.baseUrl + '/api/setOfBooks/by/tenant')
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  getCurrencyByLanguage(){
    return httpFetch.get(config.baseUrl + '/api/Currency/Language/getCurrencyByLanguage?language=chineseName')
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //获取汇率容差
  getRateDiffer(params){
    return httpFetch.get(config.baseUrl + '/api/tenant/config/by/tenantId', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //获取列表数据
  getTableData(params){
    return httpFetch.get(config.baseUrl + '/api/currency/rate/list', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //点击汇率容差的保存
  onSave(params){
    return httpFetch.post(config.baseUrl + '/api/tenant/config/input', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //查看该账套是否启用自动汇率
  getAutoRate(params){
    return httpFetch.get(config.baseUrl + '/api/currency/status/enable/auto/update', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //启用或取消启用自动汇率
  onAutoRateChange(params){
    return httpFetch.put(config.baseUrl + '/api/currency/status/enable/auto/update', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //批量更改汇率的保存
  onBatchSave(params){
    return httpFetch.put(config.baseUrl + '/api/currency/rate/list', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //获取当条数据的详情
  getCurrencyDetail(params){
    return httpFetch.get(config.baseUrl + '/api/currency/rate/select/active/one', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //获取当条数据的详情--表格数据
  getRateHistory(params){
    return httpFetch.get(config.baseUrl + '/api/currency/rate/history/list', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //编辑汇率的启用与否
  onEnableRate(params){
    return httpFetch.put(config.baseUrl + '/api/currency/status/enable', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //查询汇率历史
  onSearchHistoryRate(params){
    return httpFetch.get(config.baseUrl + '/api/currency/rate/history/list', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  onOutEditRateSave(params){
    return httpFetch.put(config.baseUrl + '/api/currency/rate', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  handleModalOK(params){
    return httpFetch.put(config.baseUrl + '/api/currency/rate', params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //新增币种时，获取币种名的option
  getCurrencyName(params){
    return httpFetch.get(`${config.baseUrl}/api/currencyI18n/select/not/created/currency`, params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },

  //新增币种时，点击保存
  onAddNewSave(params){
    return httpFetch.post(`${config.baseUrl}/api/currency/rate`, params)
      .catch((err) => {
        errorMessage(err.response);
        throw err;
      })
  },
}

